<template>
	<u-action-sheet :list="mapList" v-model="show" :mask-close-able="false" @click="toMap" @close="close"></u-action-sheet>
</template>

<script>
	export default {
		props: {
			show: {
				default: false,
				type: Boolean
			},
			latitude: {
				default: '',
				type: String
			},
			longitude: {
				default: '',
				type: String
			},
			name: {
				default: '',
				type: String
			}
		},
		data() {
			return {
				mapList: [{text: "腾讯地图"},{text: "百度地图"}, {text: "高德地图"}]
			}
		},
		
		methods: {
			close() {
				this.$emit('success')
			},
			toMap(index) {
				console.log(index)
				let latitude = this.latitude;
				let longitude = this.longitude
				let name = this.name
				
				let _this = this;
				let url = "";
				let mapIndex = index + 1;
				uni.getSystemInfo({
					success: function (res) {
						_this.system = res.system;
						console.log(_this.system)
						console.log(_this.system.indexOf('iOS'))
						if (_this.system.indexOf('iOS') > -1) {
							console.log(_this.system.indexOf('iOS'))
							switch (mapIndex) {
								case 1:
									url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
									break;
								case 2:
									url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&content=${name}&src=ios.baidu.openAPIdemo&coord_type=gcj02`;
									break;
								case 3:
									url = `iosamap://viewMap?sourceApplication=applicationName&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
									break;
								default:
									break;
							}
							
								
						}
						
						if (_this.system.indexOf('Android') > -1) {
							switch (mapIndex) {
								//下面是拼接url,不同系统以及不同地图都有不同的拼接字段
								case 1:
									//注意referer=xxx的xxx替换成你在腾讯地图开发平台申请的key
									url = `qqmap://map/geocoder?coord=${latitude},${longitude}&referer=xxx`;
									break;
								case 2:
									url = `baidumap://map/marker?location=${latitude},${longitude}&title=${name}&coord_type=gcj02&src=andr.baidu.openAPIdemo`;
									break;
								case 3:
									url = `androidamap://viewMap?sourceApplication=appname&poiname=${name}&lat=${latitude}&lon=${longitude}&dev=0`;
									break;
								default:
									break;
							}
						}
						window.location.href = url
						window.setTimeout(function() { //如果没有安装app,便会执行setTimeout跳转下载页
							uni.showToast({
								icon:'none',
								title: '本机未安装指定的地图应用'
							});
						}, 500);
						_this.$emit('success')
					}
				})
			},
		}
	}
</script>

<style>
</style>
